import 'package:bigegg/widget/image/xmm_circle_cached_network_image.dart';
import 'package:bigegg/widget/xmm_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'xmm_block_list_controller.dart';

class XmmBlockListPage extends StatefulWidget {
  const XmmBlockListPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return XmmBlockListPageState();
  }
}

class XmmBlockListPageState extends State<XmmBlockListPage>
    with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
  XmmBlockListController controller = Get.find<XmmBlockListController>();

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    controller.getBlockedList();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Column(
      children: [
        Flexible(
          child: Obx(
            () => controller.blockList.isNotEmpty
                ? ListView.builder(
                    itemCount: controller.blockList.length,
                    padding: const EdgeInsets.only(bottom: 100),
                    itemBuilder: (context, index) {
                      var item = controller.blockList.elementAt(index);
                      return Container(
                        alignment: Alignment.center,
                        height: 76.w,
                        padding: const EdgeInsets.only(
                          left: 20,
                          right: 20,
                          top: 16,
                          bottom: 16,
                        ),
                        child: Row(
                          children: [
                            XmmCircleCachedNetworkImage(
                              imageUrl: item.avatar ?? "",
                              height: 44.w,
                              width: 44.w,
                              borderColor: Colors.white,
                              borderWidth: 1,
                            ),
                            const SizedBox(width: 10),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                SizedBox(height: 2.w),
                                SizedBox(
                                  width: 200.w,
                                  child: Text(
                                    item.nickName ?? "",
                                    style: TextStyle(
                                      fontSize: 14.sp,
                                      color: const Color(0xFF202020),
                                    ),
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                  ),
                                ),
                                const Expanded(child: SizedBox(width: 5)),
                                Text(
                                  item.registerCountry ?? "",
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: const Color(0x66000000),
                                  ),
                                ),
                                SizedBox(height: 2.w),
                              ],
                            ),
                            const Expanded(child: SizedBox()),
                            GestureDetector(
                              child: Container(
                                alignment: Alignment.center,
                                decoration: BoxDecoration(
                                    color: const Color(0xFF454545),
                                    borderRadius: BorderRadius.circular(37)),
                                height: 26.w,
                                width: 71.w,
                                child: Text(
                                  "Unblock",
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: Colors.white,
                                  ),
                                ),
                              ),
                              onTap: () => controller.unblock(item),
                            )
                          ],
                        ),
                      );
                    },
                  )
                : getEmptyWidget(),
          ),
        ),
      ],
    );
  }
}
